package com.gsit.zero.hour;

import roboguice.activity.RoboActivity;
import roboguice.event.Observes;
import roboguice.inject.InjectView;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.inject.Inject;
import com.gsit.zero.hour.activity.dashboard.HomeActivity;
import com.gsit.zero.hour.component.ZeroHourAppContext;
import com.gsit.zero.hour.manager.task.ZeroHourTaskManager;

public class MainActivity extends RoboActivity {

	@InjectView(R.id.editText1)
	private EditText editText;

	@InjectView(R.id.btnSearch)
	private Button button;

	/*@Inject
	ZeroHourAppContext component;*/
	
	
	@Inject
	private ZeroHourTaskManager hourTaskManager;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		editText.setText("Change text from IOC");

		button.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				eventManager.fire(new MainEvent(EvenType.SUBMIT));
				
			}
		});
	}
	
	 protected void handleMainEvent( @Observes MainEvent event ) {
	        Toast.makeText(this, "You won't regret it!", Toast.LENGTH_LONG).show();
	        if(event.getEventType() == EvenType.SUBMIT){
	        	 /*MainActivity.this.startActivity(homeIntent);*/
	        	hourTaskManager.process(this, event.homeIntent);
	        }
	       
	 }

	class MainEvent {
	    private EvenType evenType;
	    Intent homeIntent;
	    public MainEvent(EvenType evenType){
	    	this.evenType = evenType;
	    	onCreate();
	    }
	   
	    
	    private void onCreate(){
	    	if(homeIntent == null)	homeIntent = new Intent(MainActivity.this,HomeActivity.class);
	    }
		
	    EvenType getEventType(){
			return evenType;
		}
		
	}
	enum EvenType{
		SUBMIT
	}
}
